package com.zxl.jdk8test;

/**
 * lambda语法说明
 * 任意接口的方法都可以使用lambda表达式实现,参考MyTest类
 * @author zxl
 *
 */
public interface LambdaSyntax {
    
    /**
     *  () -> {}                // No parameters; result is void
        () -> 42                // No parameters, expression body
        () -> null              // No parameters, expression body
        () -> { return 42; }    // No parameters, block body with return
        () -> { System.gc(); }  // No parameters, void block body
        
        () -> {                 // Complex block body with returns
          if (true) return 12;
          else {
            int result = 15;
            for (int i = 1; i < 10; i++)
              result *= i;
            return result;
          }
        }                          
        (int x) -> x+1              // Single declared-type parameter
        (int x) -> { return x+1; }  // Single declared-type parameter
        (x) -> x+1                  // Single inferred-type parameter
        x -> x+1                    // Parentheses optional for
                                    // single inferred-type parameter
        
        (String s) -> s.length()      // Single declared-type parameter
        (final String s) -> s.length()      // Single declared-type parameter
        (Thread t) -> { t.start(); }  // Single declared-type parameter
        s -> s.length()               // Single inferred-type parameter
        t -> { t.start(); }           // Single inferred-type parameter
        
        (int x, int y) -> x+y  // Multiple declared-type parameters
        (x, y) -> x+y          // Multiple inferred-type parameters
        (x, int y) -> x+y    // Illegal: can't mix inferred and declared types
        (x, final y) -> x+y  // Illegal: no modifiers with inferred types
     */
}
